<script>
import { USER_CURRENT_LOCATION_KEY } from "@/utils/location";
import { appRemoveStorage } from "@/utils/storage";

export default {
  onLaunch: function () {
    //每次冷启动，到首页之前，需要清理的缓存
    const storages = [USER_CURRENT_LOCATION_KEY];
    storages.forEach((s) => {
      appRemoveStorage(s);
    });
    uni.hideTabBar();
    console.log("App Launch");
    this.$store.dispatch("sp-common/base/getUserWxConfig")
    this.$store.dispatch("sp-common/auth/userLogin");
  },
  onShow(options) {
    const {
      "sp-common/pay": { payResolve, payReject },
    } = this.$store.state;
    if (payResolve && payReject) {
      const data = options.referrerInfo?.extraData?.data;
      if (!data) {
        uni.showToast({ title: "支付失败", icon: "none", duration: 2000 });
        payReject({ code: -1, msg: "支付失败" });
        options.referrerInfo = {};
        this.$store.commit("sp-common/pay/SET_PAY_RESULT");
        return;
      }
      payResolve(JSON.parse(JSON.stringify(data)));
      options.referrerInfo = {};
      this.$store.commit("sp-common/pay/SET_PAY_RESULT");
    }
  },
  onHide: function () {
    console.log("App Hide");
  },
};
</script>

<style lang="scss">
/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss";
@import "/static/iconfont/iconfont.css";
@import "static/styles/index.scss";
@import "static/styles/common.scss";
</style>
